#include <tsin/library/DynamicBasicType.hpp>

#include <tsin/util/Logger.hpp>

using namespace tsin;

DynamicBasicType::DynamicBasicType(int i)
{
        type = 'E';
        data.i = i;
}

DynamicBasicType::DynamicBasicType(float f)
{
        type = 'N';
        data.f = f;
}

DynamicBasicType::DynamicBasicType(bool b)
{
        type = 'B';
        data.b = b;
}

DynamicBasicType::DynamicBasicType(const char *s)
{
        type = 'S';
        data.s = s;
}

void DynamicBasicType::reinit()
{
}

char DynamicBasicType::getDescriptor()
{
        return type;
}

int DynamicBasicType::getInt()
{
        if (type == 'N')
                return static_cast<int>(data.f);
        else if (type == 'E')
                return data.i;
        return DynamicObject::getInt();
}

float DynamicBasicType::getFloat()
{
        if (type == 'N')
                return data.f;
        return DynamicObject::getFloat();
}

bool DynamicBasicType::getBool()
{
        if (type == 'B')
                return data.b;
        return DynamicObject::getBool();
}

const char *DynamicBasicType::getString()
{
        if (type == 'S')
                return data.s;
        return DynamicObject::getString();
}
